package presenter.impl;

import android.os.Handler;

import bean.UserBean;
import model.OnLoginListener;
import model.impl.UserLoginModel;
import presenter.IUserLoginPresenter;
import view.IUserLoginView;

/**
 * 具体类：用户登录逻辑交互
 */
public class UserLoginPresenter implements IUserLoginPresenter {
    private UserLoginModel mUserModel;
    private IUserLoginView mUserLoginViewImpl;
    private final Handler handler = new Handler();

    public UserLoginPresenter(IUserLoginView mUserLoginViewImpl) {
        this.mUserLoginViewImpl = mUserLoginViewImpl;
        mUserModel = new UserLoginModel();
    }

    @Override
    public void login() {
        mUserModel.login(mUserLoginViewImpl.getUsername(),
                mUserLoginViewImpl.getPassword(),
                new OnLoginListener() {

                    @Override
                    public void onLoginSuccess(UserBean user) {
                        //处理成功后的逻辑
                        getPersonalInfo(user);
                    }

                    @Override
                    public void onLoginFailed(final String result) {
                        handler.post(new Runnable() {
                            @Override
                            public void run() {
                                mUserLoginViewImpl.showLoginError(result);
                            }
                        });
                    }
                });
    }

    @Override
    public void getPersonalInfo(UserBean userBean) {

    }

}